<template>
	<view class="container">

		<view class="formBox" v-for="(item,index) in houseList">
			<u-gap height="16"></u-gap>
			<view class="housingInfo-num">{{'房屋信息'+ (index+1)}}</view>
			<!-- <u--text :size="28" :text="'房屋信息'"+{{index}}></u--text> -->
			<u-gap height="16"></u-gap>
			<view class="line">
				<view class="line-title">所属业主：</view>
				<u--text :size="26" color="#999999" mode="name" :text="item.username"></u--text>
			</view>
			<view class="line">
				<view class="line-title">联系电话：</view>
				<u--text :size="26" color="#999999" mode="phone" :text="item.phonenumber"></u--text>
			</view>
			<view class="line">
				<view class="line-title">地址：</view>
				<u--text :size="26" color="#999999" :text="item.alladdress"></u--text>
			</view>
			<view class="line">
				<view class="line-title">房屋面积：</view>
				<u--text :size="26" color="#999999" :text="item.area+'㎡'"></u--text>
			</view>
			<u-gap height="16"></u-gap>
			<view class="line line-btn">
				<u-button type="primary" style="width: 40%; height: 100%;font-size: 24rpx;" @click="getEdit(item)"
					:plain="true" text="编辑"></u-button>
				<u-button type="error" style="width: 40%; height: 100%;" @click="getDelete(item,index)" :plain="true"
					text="删除"></u-button>
			</view>
		</view>
		<template  v-if="houseList.length == 0">
			<view class="tabsContent">
				<u-empty mode="data" width="280" height="280" textSize="28"
					icon="http://cdn.uviewui.com/uview/empty/data.png" text="暂无房屋信息"></u-empty>
			</view>
		</template>

		<u-gap height="164"></u-gap>
		<view class="bottomBtn">
			<u-button type="primary" text="新建房屋信息" @click="getbuilthousInfo"></u-button>
		</view>
		<u-modal :show="deleteShow" :title="deleteTitle" showCancelButton buttonReverse :zoom="false"
			:closeOnClickOverlay="true" @confirm="deleteConfirm" @cancel="deleteShow = false"
			@close="deleteShow = false "></u-modal>
		<u-loading-page :loading="loading"></u-loading-page>
	</view>
</template>

<script>
	import api from "@/api/api.js"
	import {
		mapActions,
		mapState,
		mapMutations
	} from "vuex"
	export default {
		name: '',
		components: {},
		data() {
			return {
				loading: false,
				deleteShow: false,
				deleteTitle: '是否确认删除',
				deleteId: null,
				houseList: []
			}
		},
		created() {

		},
		onShow() {
			this.getMyhouse()
		},
		onPullDownRefresh() {
			this.getMyhouse()
			this.loading = true;
			setTimeout(() => {
				uni.stopPullDownRefresh();
			}, 500);
			setTimeout(() => {
				this.loading = false;
			}, 1000);

		},
		mounted() {},
		destroyed() {},
		methods: {
			// 获取我的房屋信息
			getMyhouse() {
				let userInfo = uni.getStorageSync('userInfo')
				let data = {
					userId: userInfo.id
				}
				api.getMyhouse(data).then(res => {

					console.log('getMyhouse', res)
					if (res.data.code == 200) {
						this.houseList = res.data.rows;
					}

				}).catch(err => {
					console.log(err)
				})
			},
			// 新建房屋信息
			getbuilthousInfo() {
				uni.$u.route({
					type: "navigateTo",
					url: "/pages/housingInfo/form",
					params: {
						state: 'new'
					}
				})
			},
			// 编辑
			getEdit(item) {
				uni.$u.route({
					type: "navigateTo",
					url: "/pages/housingInfo/form",
					params: {
						state: 'edit',
						editId: item.houseId
					}
				})
			},
			// 删除
			getDelete(item, index) {
				console.log(item, index)
				this.deleteShow = true;
				this.deleteTitle = `是否确认删除 房屋信息${index+1}`
				this.deleteId = item.houseId
			},
			deleteConfirm() {

				let data = {
					id: this.deleteId
				}
				this.deleteShow = false;
				this.loading = true;

				api.getHouseRemove(data).then(res => {
					if (res.data.code == 200) {
						this.getMyhouse()
						setTimeout(() => {
							this.loading = false;
							uni.$u.toast('删除成功')
						}, 300)
					}
				}).catch(err => {
					uni.$u.toast(err.msg)
				})


			}

		}
	}
</script>

<style lang="scss" scoped>
	.container {
		width: calc(100% - 32rpx);
		padding: 0 16rpx;
	}

	.tabsContent {
		margin-top: 16rpx;
		width: 100%;
		background-color: #FFFFFF;
		height: 600rpx;
	}

	.formBox {
		width: calc(100% - 64rpx);
		padding: 16rpx 32rpx;
		border-radius: 8rpx;
		background-color: #FFFFFF;
		margin: 32rpx 0;

		.housingInfo-num {
			font-size: 28rpx;
			font-weight: bold;
		}

		.line-btn {
			justify-content: space-around;
			height: 60rpx;
		}

		.line {
			display: flex;
			width: 100%;
			min-height: 60rpx;
			align-items: center;

			.line-title {
				width: 200rpx;
				font-size: 28rpx;

			}
		}
	}

	.bottomBtn {
		position: fixed;
		width: calc(100% - 63rpx);
		padding: 32rpx;
		bottom: 0;
		left: 0;
		background-color: #FFFFFF;
		display: flex;
		align-items: center;
		justify-content: center;
		box-shadow: 0rpx 1rpx 8rpx 0rpx #e5e5e5;
	}
</style>
